package com.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.Environment;

import com.bean.ClientFactory;
import com.fasterxml.jackson.databind.ObjectMapper;

@Configuration
@ComponentScan("com")
@PropertySource("classpath:conf.properties")
@EnableAspectJAutoProxy
public class SpringConfig {

	@Autowired // 将Property注入到env中来
	private Environment env;

	/*
	 * Java中配置占位符的方式,需要此Bean和上面的 @PropertySource(
	 * "classpath:/conf.properties")*注解支持,而后可以在Component中使用
	 * {@value使用占位符注入属性值}**@return
	 */

	@Bean
	public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
		return new PropertySourcesPlaceholderConfigurer();
	}

	@Bean
	public Environment env() {
		return env;
	}

	// 使用FactoryBean方式
	@Bean(name = "client")
	public ClientFactory clientFactory() {
		return new ClientFactory();
	}

	@Bean
	public ObjectMapper jsonMapper(){
		return new ObjectMapper();
	}
}
